<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;
use app\index\ComplaintModel;
use app\index\controller\Basecontroller;
use app\index\model\ComplaintModel as ModelComplaintModel;

// use app\index\model\ComplaintModel as ModelComplaintModel;

class Complaint extends Basecontroller
{
  // 初始化
  protected $complaint = null;
  function __construct()
  {
    parent::__construct();
    $this->complaint = new ModelComplaintModel();
  }
  // 反馈信息
  public function add(){
    $request=Request::instance();
    $content = $request->post('content');//反馈信息
    $token = $request->post('token');//用户token
    // return $content;
    // 根据用户token获取用户信息
    $tokenData = json_decode($this->redis->get($token),true);
    // var_dump($tokenData);
    $uid = $tokenData['uid'];//用户id
    $u_nickname = $tokenData['nickname'];//用户昵称
    // 将数据添加进数据库
    $model = new ModelComplaintModel();
    $result = $model->add_centent($uid,$u_nickname,$content);
    // 返回结果
    if($result==0){
      return res(1000,'感谢您的反馈，我们会尽快处理您的建议');
    }else{
      return res(1001,'不好意思，未能获取到您提交的反馈，如有需要，可以再次提交，谢谢!');
    }
  }
}